package com.fowo.api.pda.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fowo.api.common.model.R;
import com.fowo.api.controller.purchase.vo.WarehouseBinParam;
import com.fowo.api.entity.WarehouseBin;
import com.fowo.api.model.stock.in.StockInSearchParamPo;
import com.fowo.api.model.stock.in.product.StockInProductItemVo;
import com.fowo.api.model.stock.in.product.StockInProductVo;
import com.fowo.api.pda.model.PdaPutawayVo;
import com.fowo.api.pda.model.ProductInventoryVo;
import com.fowo.api.pda.model.PutawayParamPo;
import com.fowo.api.pda.model.PutawayVo;
import com.fowo.api.pda.service.PdaPutawayService;
import com.fowo.api.service.StockInProductService;
import com.fowo.api.user.model.JwtUserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Tag(name = "PDA上架管理")
@RequestMapping("/api/pda/putaway")
@RestController
public class PdaPutawayController {
    @Resource
    private PdaPutawayService service;
    @Resource
    private StockInProductService stockInProductService;

    @Operation(summary = "订单列表分页查询")
    @GetMapping("/page")
    public R<Page<PdaPutawayVo>> getPage(PutawayParamPo search) {
        return R.data(service.pageSearch(search));
    }

    @Operation(summary = "获取单据详情")
    @GetMapping("/{id}")
    public R<PdaPutawayVo> getInfo(@PathVariable Long id){
        return R.data(() -> service.getInfo(id));
    }

    @Operation(summary = "获取产品上架信息")
    @GetMapping("")
    public R<StockInProductItemVo>  getProductItemVo(Long id,String sku){
        return R.data(() -> service.getProductItemVo(id, sku));
    }

    @Operation(summary = "推荐仓位")
    @GetMapping("/bin")
    public R<List<String>> getRecommendBin(Long stockId,String sku,Long shopId,String fnsku){
        return R.data(() -> service.getRecommendBin(stockId,sku,shopId,fnsku));
    }

    @Operation(summary = "获取仓库暂存仓位")
    @GetMapping("/getBinByWarehouse")
    public R<List<WarehouseBin>> getBinByWarehouse(Long stockId) throws Exception {
        return R.data(service.getBinByWarehouse(stockId));
    }

    @Operation(summary = "获取暂存位产品")
    @GetMapping("/getProduct")
    public R<List<ProductInventoryVo>> getProduct(Long stockId,Long binId,String sku)throws Exception {
        return R.data(service.getProduct(binId, sku));
    }

    @Operation(summary = "采购上架")
    @PostMapping
    public R putaway(@RequestBody PutawayVo vo) throws Exception {
        return R.run(() -> service.putaway(vo));
    }
}
